<script language="javascript" type="text/javascript" src="../admin/p_guia/valida_form.js"></script>
<?php 
	include "../admin/p_usuario/valida_credenciais.php";
	
	$valCr = new valida_credenciais();
	//$nivel define o array de acessos, ou seja, os grupos que podem acessar essa pagina
	$nivel = array(1);
	if(!($valCr->validar($nivel))){
		header('Location: index.php?pg=denied');
	}
	
	$id = $_GET['i'];
	$resul = mysql_query("SELECT * FROM `empresas` WHERE `empresas`.`id_empresa` = $id");
	$empresa = mysql_fetch_array($resul);
	
	$resultado = mysql_query("SELECT * FROM `categorias` WHERE `categorias`.`id_categoria` = {$empresa['categoria_id']}");
	$categoria = mysql_fetch_array($resultado);
?>
<div class="form">
	<div class="row">
		<div class="col-md-12">
			<div class="page-header">
				<h2>Editar dados da Empresa</h2>
			</div>
		</div>
	</div>
	<div class="row">
	<div class="col-md-3">
		<?php include "../admin/p_guia/actions-empresa.php"; ?>
		
		</div><!-- end col md 3 -->
		<div class="col-md-9">
		<!-- HEAD DE FORMULÃ�RIO -->
		<div class="panel panel-default">
			<div class="panel-heading"><h5>Formul&aacuterio para editar informa&ccedil&otildees da Empresa</h5></div>
			<div class="panel-body">
			<!-- FORMULÃ�RIO -->
			<form  method="post" name="form1" action="../admin/p_guia/editar.php" enctype="multipart/form-data">
				<div class="row">
					<div class="col-md-12 form-group"><h6>(<span class="text-danger">*</span>) Campos de preenchimento obrigat&oacuterio.</h6></div>
				</div>
				<input type="hidden" name="idempresa" value="<?php echo $empresa['id_empresa'];?>">
				
				<div class="row">
					<div class="form-group col-md-9">
						<label for="empresa">Empresa (<span class="text-danger">*</span>)</label>
    					<input type="text" class="form-control" name="empresa" id="empresa" value="<?php echo $empresa['nome_empresa'];?>">
					</div>
				</div>
				<div class="row">
					<div class="form-group col-md-7">
						<label for="endereco">Endere&ccedilo (<span class="text-danger">*</span>)</label>
    					<input type="text" class="form-control" id="endereco" name="endereco" value="<?php echo $empresa['endereco'];?>">
					</div>
					<div class="form-group col-md-2">
						<label for="cep">CEP (<span class="text-danger">*</span>)</label>
    					<input type="text" class="form-control" id="cep" name="cep" maxlength="10" onkeypress="MascaraCep(form1.cep);" onBlur="ValidaCep(form1.cep)" value="<?php echo $empresa['cep'];?>">
					</div>
				</div>
				<div class="row">
					<div class="form-group col-md-9">
						<label for="fanpage">Fanpage</label>
    					<input type="text" class="form-control" name="fanpage" id="fanpage" value="<?php echo $empresa['fanpage'];?>">
					</div>
				</div>
				<div class="row">
					<div class="form-group col-md-9">
						<label for="link">Link(Site da empresa)</label>
    					<input type="text" class="form-control" name="link" id="link" value="<?php echo $empresa['link'];?>">
					</div>
				</div>
				<div class="row">
					<div class="form-group col-md-3">
						<label for="tel">Telefone</label>
    					<input type="text" class="form-control" id="tel" name="tel" placeholder="Ex:(67) 0000-0000" maxlength="14" onkeypress="MascaraTelefone(form1.tel);" value="<?php echo $empresa['telefone'];?>">
					</div>
					<div class="form-group col-md-6">
						<label for="email">Email (<span class="text-danger">*</span>)</label>
    					<input type="text" class="form-control" id="email" name="email" value="<?php echo $empresa['email'];?>">
					</div>
				</div>
				<div class="row">
					<div class="form-group col-md-6">
						<label for="categoria">Categoria (<span class="text-danger">*</span>)</label>
    					<select name="categoria" id="categoria" class="form-control">
		          			<option value='selecione'>Selecione...</option>
							<?php
								$query = mysql_query("SELECT `id_categoria`, `nome_categoria`, `status` FROM `categorias` WHERE `status` LIKE '1'");
								while($lista = mysql_fetch_array($query)) { 
									if($lista['id_categoria'] == $categoria['id_categoria']){?> 
										<option value="<?php echo $lista['id_categoria']; ?>" selected><?php echo $lista['nome_categoria']; ?></option>
									<?php }else{?>
										<option value="<?php echo $lista['id_categoria']; ?>"><?php echo $lista['nome_categoria']; ?></option>
							<?php 
									}
								}?>
			          	</select>
					</div>
				</div>
				<div class="row">
					<div class="form-group col-md-6">
						<label for="status">Situa&ccedil&atildeo (<span class="text-danger">*</span>)</label>
    					<select name="status" id="status" class="form-control">
		          			<option value='selecione'>Selecione...</option>
		          			<?php if($empresa['status'] == 1){ ?>
								<option value="<?php echo $empresa['status']; ?>" selected>Empresa Ativa</option>
								<option value="0">Empresa Inativa</option>
							<?php } else{?>
								<option value="<?php echo $empresa['status']; ?>" selected>Empresa Inativa</option>
								<option value="1">Empresa Ativa</option>
							<?php }?>
		          		</select>
		          	</div>
				</div>
				
				<br>
				<div class="row">
					<div class="form-group col-md-2">
						<input type="submit" value="Salvar" class="btn btn-default" name="enviar" onclick="return valida()" >
					</div>
				</div>
			</form>
			</div>
		</div>

		</div><!-- end col md 12 -->
	</div><!-- end row -->
</div>
			